package com.xuanyaun.coreutils.file

import android.util.Log
import java.io.File

/**
 * @FileName:
 * @Description:
 * @author ken.luo
 * @date 2023/4/4
 * @version V1.0
 * @email 424533553@qq.com
 */
object FileUtils {
    val TAG = "FileUtils"
    
    /**
     * 检测文件存在
     *
     * @param filePath
     * @return
     */
    fun checkFile(filePath : String) : Boolean {
        //boolean result = FileUtil.fileIsExist(filePath);
        var result = false
        val mFile = File(filePath)
        if (mFile.exists()) {
            result = true
        }
        val logStr = if (result) "文件已存在" else "文件不存在"
        Log.e(TAG,"$logStr, path = $filePath")
        return result
    }
    
    
    /**
     * 获取照片的mine_type
     *
     * @param path
     * @return
     */
     fun getPhotoMimeType(path: String): String? {
        val lowerPath = path.toLowerCase()
        if (lowerPath.endsWith("jpg") || lowerPath.endsWith("jpeg")) {
            return "image/jpeg"
        } else if (lowerPath.endsWith("png")) {
            return "image/png"
        } else if (lowerPath.endsWith("gif")) {
            return "image/gif"
        }
        return "image/jpeg"
    }
    
}